package com.example.customer01.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Aspect
@Component
public class ValidationAspect {
    private static final Logger logger = LoggerFactory.getLogger(ValidationAspect.class);

    @Pointcut("execution(* com.example.customer01.service.*.*(..))")
    public void serviceLayer() {}

    @Before("serviceLayer()")
    public void validateParameters(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getSimpleName();

        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            if (arg == null) {
                logger.warn("参数验证警告: {}.{} 的第 {} 个参数为空", className, methodName, i + 1);
            } else if (arg instanceof String && !StringUtils.hasText((String) arg)) {
                logger.warn("参数验证警告: {}.{} 的第 {} 个参数为空字符串", className, methodName, i + 1);
            }
        }
    }
} 